﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using org.xisoft.game.utils.game;

namespace org.xisoft.game.GobangModule.Chess.Algorithms
{
    /**
     * 极大极限值
     */
    class NegaMaxAlgorithm:AiAlgorithm
    {

        public override MoveAction DoNextMove(GobangBroad gobangBroad, int depth)
        {
            List<MoveAction> points = GetAllCanMoves(gobangBroad);
            MoveAction bestMove = null;

            foreach (MoveAction move in points)
            {
                if (depth > 0)
                {
                    gobangBroad.DoNextMove(move.ToX, move.ToY);
                    MoveAction action = DoNextMove(gobangBroad, depth - 1);
                    gobangBroad.Undo();

                    if (action != null)
                        move.Score -= action.Score;
                }

                if (bestMove == null || bestMove.Score < move.Score)
                    bestMove =move;
                

            }

            return bestMove;
        }
    }
}
